<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="答复内容"></uni-navbar></view>

		<view class="detail-info">
			<view class="info-title">
				<view class="title-top">{{ title }}</view>
			</view>
		</view>

		<view class="form-box">
			<u-form :model="form" ref="uForm">
				<u-form-item class="form-item" required label="发文字号" prop="wordSize"><u-input v-model="form.wordSize" type="text" :maxlength="30" placeholder="请输入发文字号" /></u-form-item>
				<u-form-item class="form-item" required label="签发人" prop="issueUser"><u-input v-model="form.issueUser" type="text" :maxlength="30" placeholder="请输入签发人" /></u-form-item>
				<u-form-item class="form-item" required label="答复类型" prop="replyType">
					<u-input v-model="type" type="select" :select-open="typeShow" placeholder="请选择答复类型" @click="typeShow = true" />
					<u-select :list="typeList" v-model="typeShow" @confirm="typeConfirm"></u-select>
				</u-form-item>
				<u-form-item class="form-item" required label="是否公开">
					<u-radio-group v-model="isOpen" input-align="right">
						<u-radio v-for="(item, index) in openList" :key="index" :name="item.name">{{ item.value }}</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item class="form-item" label="不公开理由" v-if="isOpen == '0'"><u-input v-model="form.remark1" type="text" :maxlength="30" placeholder="请输入不公开理由" /></u-form-item>
				<u-form-item class="form-item" required label="答复内容" label-position="top" label-width="240" prop="replyContent">
					<u-input v-model="form.replyContent" type="textarea" input-align="left" placeholder="请输入答复内容" :clearable="false" :height="160" />
				</u-form-item>
				<u-form-item class="form-item" label=" " label-position="top"><uni-file-upload :type="['all', 'image', 'audio']" :limit="10"></uni-file-upload></u-form-item>

				<u-form-item class="form-item" required label="联系人" prop="linker"><u-input v-model="form.linker" type="text" :maxlength="30" placeholder="请输入联系人" /></u-form-item>
				<u-form-item class="form-item" required label="联系电话" prop="linkerTel"><u-input v-model="form.linkerTel" type="text" :maxlength="30" placeholder="请输入联系电话" /></u-form-item>
			</u-form>

			<view class="fiexd-btm" v-if="$sysBtns('tagtqk')"><u-button type="error" @click="confirm">提交</u-button></view>
		</view>
	</view>
</template>

<script>
import uniFileUpload from '@/components/uni-all-uploader.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniFileUpload
	},
	data() {
		return {
			title: '',

			type: '',
			typeShow: false,
			typeList: [],

			isOpen: '0',
			openList: [
				{
					name: '0',
					value: '不公开'
				},
				{
					name: '1',
					value: '公开'
				}
			],

			form: {
				motionId: null,
				wordSize: null,
				clientCode: null,
				createBy: null,
				issueUser: null,
				linker: null,
				linkerTel: null,
				remark1: null,
				replyType: null,
				replyContent: null
			},
			rules: {
				wordSize: [
					{
						required: true,
						message: '请输入发文字号',
						trigger: 'change'
					}
				],
				issueUser: [
					{
						required: true,
						message: '请输入签发人',
						trigger: 'change'
					}
				],
				type: [
					{
						required: true,
						message: '请选择沟通类型',
						trigger: 'change'
					}
				],
				replyContent: [
					{
						required: true,
						message: '请输入答复内容',
						trigger: 'change'
					}
				],
				linker: [
					{
						required: true,
						message: '请输入联系人',
						trigger: 'change'
					}
				],
				linkerTel: [
					{
						required: true,
						message: '请输入联系电话',
						trigger: 'change'
					}
				]
			},

			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.$store.commit('filePush', []);

		this.title = option.title;
		if (option && option.motionId) {
			this.form.motionId = option.motionId;
			this.form.deptId = option.deptId;
		}

		this.loadDict('motion_reply_type', 'typeList');
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	onUnload() {
		this.$store.commit('filePush', []);
	},
	computed: {
		...mapState(['userInfo', 'fileList'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.form.clientCode = this.clientCode;
				this.form.createBy = this.userId;
			} else {
				this.$logout();
			}
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this[list] = [];
				res.data.forEach((item) => {
					this[list].push({
						value: item.dictValue,
						label: item.dictName
					});
				});
			});
		},
		typeConfirm(e) {
			this.type = e[0].label;
			this.form.replyType = e[0].value;
		},
		confirm() {
			this.$refs.uForm.validate((valid) => {
				if (!valid) {
					return false;
				} else {
					let data = {};

					this.form.isOpen = this.isOpen;

					data = {
						clientCode: this.clientCode,
						currentUserId: this.userId,
						fileList: this.fileList,
						motionHanlderReply: this.form
					};
					this.$request('/motion/handler/reply/add', data).then((res) => {
						this.$msg(res.msg);
						setTimeout(() => {
							let pre = this.$prePage();
							if (pre && pre.loadData) {
								pre.loadData('refresh');
							}
							uni.navigateBack();
						}, 500);
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.detail-info {
	.info-title {
		margin-bottom: 0;
	}
}

.info-h2 {
	padding: 0 30upx;
	font-size: 17px;
	font-weight: bold;
	color: #ce1617;
	line-height: 88upx;
	background-color: #f9fafc;
}

.info-inner {
	display: flex;

	.item {
		width: 50%;
	}
}

.form-box {
	.form-item {
		@include mp-flex;
		border-top: 20upx solid #f5f7fa;
	}
}

.fiexd-btm {
	position: static;
	padding: 30upx;
}
</style>
